Stats: fix CSV export filenames for selected date ranges - #113340
Merged
Conversation
|
WordPress.com
Automattic for Agencies
|
Nikschavan
marked this pull request as ready for review
August 7, 2026 03:11
Use the custom range query dates (and period) for download filenames so exports match the selected selection instead of a single period unit. Co-authored-by: Cursor <cursoragent@cursor.com>
The Emails summary export returns the latest 30 emails with no date scoping, so a period date range in the filename was misleading. Add an includeDates option to getStatsCsvFileName and turn it off for the Emails summary download.
Nikschavan
force-pushed
the
fix/stats-420-csv-export-filenames
branch
from
August 7, 2026 03:12
056b671 to
39af32b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Stats CSV export filenames so they reflect the user’s selected date range (especially for custom multi-month/single-month ranges), and updates the Emails summary CSV export to omit date/period segments because that export isn’t date-scoped.
Changes:
- Extracted a shared
getStatsCsvFileNamehelper and updatedStatsDownloadCsvto use it (including anincludeDatesoption). - Preferred custom range query params (
start_date/date/period) when present to build filenames that match the actual selection. - Added regression tests covering the STATS-420 custom-range cases and the Emails
includeDates=falsebehavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| client/my-sites/stats/stats-email-summary/index.jsx | Passes includeDates={ false } for the Emails summary CSV export to omit misleading date/period segments. |
| client/my-sites/stats/stats-download-csv/index.jsx | Switches filename construction to the extracted helper and threads through includeDates. |
| client/my-sites/stats/stats-download-csv/get-stats-csv-filename.js | Adds the helper that builds CSV filenames from either custom query ranges or legacy period bounds. |
| client/my-sites/stats/stats-download-csv/test/get-stats-csv-filename.js | Adds regression coverage for custom-range filename generation and the includeDates=false behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Custom date ranges force query.period to day for the API, which produced misleading day- prefixes like posts-day-01/01/2026-08/06/2026.csv. Drop the period segment when start_date/date are present; keep it for standard period views.
Strict-parse custom start_date/date values and fall back to period bounds when either is invalid, and format custom dates with the period moment locale. Restore the previous moment locale after tests to avoid leaks.
kangzj
approved these changes
Aug 7, 2026
kangzj
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the filename logic, the callers, and the tests — looks good.
- Custom-range detection (strict-parsed
start_date+date) matches howsummary/index.jsxbuildsmoduleQuery, and omitting the period segment is correct sincequery.periodis forced todayfor custom ranges. - Checked all four
DownloadCsvcall sites:utm-export-buttonpasses no query so behavior is unchanged, andincludeDates={false}for the all-time Emails summary is consistent with why that surface ignores the period. - Earlier Copilot feedback (strict parsing, test locale leak) is already addressed in a87c262.
- New unit tests pass locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes STATS-420
Proposed Changes
start_date/date) when building Stats CSV download filenames, so the filename matches the selected range instead of a single period unit around the start date.dayfor the API and is not meaningful in the filename), e.g.…-posts-01/01/2026-08/06/2026.csvinstead of…-posts-day-01/01/2026-08/06/2026.csv.getStatsCsvFileNameand add regression coverage for the STATS-420 cases (multi-month and single-month custom ranges).includeDatesoption, so it downloads as<site-slug>-emails.csv.Why are these changes being made?
Exported report filenames did not reflect the selected date range. For a Jan 1–Aug 6 selection the file looked like a January-only month export, and for Jan 1–31 the filename used a day period with identical start/end dates. The CSV contents were correct; only the filename was wrong.
Custom date ranges also always forced
query.periodtoday, which left a misleadingday-prefix in every custom-range export even after the dates were fixed.The Emails summary report has no date picker and its export is not date-scoped — it always returns the latest 30 emails — so a date range in that filename was misleading and is now omitted.
Testing Instructions
…-posts-01/01/2026-08/06/2026.csv), not…-posts-day-…or a single month.…-day-01/01/2026-01/01/2026.csv.…-month-…)./stats/day/emails/<site>) and download CSV. Confirm the filename is<site-slug>-emails.csvwith no period or dates.yarn test-client client/my-sites/stats/stats-download-csv/test/get-stats-csv-filename.jsPre-merge Checklist
Made with Cursor